package com.example.mynote.base;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

public abstract class MyAdapter<T> extends BaseAdapter {
    private List<T> data;
    private int Layout;

    public MyAdapter(List<T> data, int layout) {
        this.data = data;
        Layout = layout;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        if (convertView == null) {
            view = LayoutInflater.from(parent.getContext()).inflate(Layout, null);
        } else {
            view = convertView;
        }
        cover(view, data.get(position), position);
        return view;
    }

    protected abstract void cover(View v, T bean, int pos);
}
